const http = require('http')


const Router = {}

function use (obj) {
  Object.assign(Router,obj)
}

console.log(Router)


function start () {
  http.createServer((req,res) => {
    const myUrl = new URL(req.url,'http://127.0.0.1')
    console.log(myUrl.pathname)
    const routerFun = Router[myUrl.pathname] ? Router[myUrl.pathname] : Router['/404']
    routerFun(req,res)
  }).listen(3000,() => {
    console.log('3000 runing')
  })
}

exports.start = start
exports.use = use